<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path=request.getContextPath();
	String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>   
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录</title>
	<style>
		body{
			font-size:14px;
		}
	</style>
</head>
<body>
	<input type="hidden" id="userId" value="${manager.iUserId}"/>
	<input type="hidden" id="userName" value="${manager.sUserName}"/>
	<div align="center">
	<table>
		<tr>
			<td>输入旧密码</td>
			<td><input type="password" 
				title="输入6-16位的英文或数字" id="sPassword" name="sPassword"
				onchange="doChange(this)" value=""/></td>
			<td id="td1"></td>
		</tr>
		<tr>
			<td>输入新密码</td>
			<td><input type="password" pattern="\w{6,16}"
				title="输入6-16位的英文或数字" id="sPassword1" name="sPassword"/></td>
		</tr>
		<tr>
			<td>重新输入新密码</td>
			<td><input type="password" pattern="\w{6,16}"
				title="输入6-16位的英文或数字" id="sPassword2" name="sPassword" /></td>
		</tr>
		<tr><td><input type="button" value="确定" onclick="doclick()"/></td></tr>
	</table>
	</div>
	
</body>
	<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
	<script type="text/javascript">
		var flag = false;
		function doChange(textObj) {
			var value = textObj.value;
			var obj = new Object();
			if (value == "") {
				alert("请填写旧密码");
			} else {
				obj.sPassword = value;
				
				$.ajax({
					// 请求的地址
					url : "manager/passwordUpdate.action",
					// 是否是异步。
					async : false,
					// 回执的数据类型，默认为普通字符串
					dataType : "json",
					// 请求的数据
					data : {"sUserName":$("#userName").val(),"sPassword":value},
				
					// 请求后的回调方法。{"status":?,"msg":?}
					success : function(result) {
						console.log(result);
						if (result["status"] == 2) {
							$("#td1").text(result["msg"]);
							flag = false;
						} else if (result["status"] == 1) {
							$("#td1").text(result["msg"]);
							flag = true;
						}
					},
					type : "POST"
				});
			}
		}
	
		function doclick(){
			if($("#sPassword1").val() !=$("#sPassword2").val()){
				alert("你输入的密码不匹配，请再试一次。");
				return false;
			}
			if(!flag){
				alert("旧密码错误，请重新输入！");
				return false;
			}
			window.location="manager/update.action?iUserId="+$("#userId").val()+"&sPassword="+$("#sPassword2").val();
		}
	</script>
</html>